<template>
	<div class="group-item" :class="active ? 'active' : ''" @contextmenu.prevent="showRightMenu($event)">
		<div class="avatar">
			<head-image :size="45" :name="regionGroup.remark" :url="regionGroup.headImage"> </head-image>
		</div>
		<div class="group-info">
			<div class="group-name">{{regionGroup.remark}}
        <span style="margin-left: 10px">
          <el-tag type="success" v-if="regionGroup.joinType===1">常驻</el-tag>
          <el-tag type="warning" v-if="regionGroup.joinType===0">临时</el-tag>
        </span>
      </div>
		</div>
    <right-menu v-show="menu && rightMenu.show" :pos="rightMenu.pos" :items="rightMenu.items"
                @close="rightMenu.show=false" @select="onSelectMenu"></right-menu>
    <slot></slot>
	</div>
</template>

<script>
	import HeadImage from '../common/HeadImage.vue';
  import RightMenu from "../common/RightMenu.vue";

	export default {
		name: "regionGroupItem",
		components: {
			HeadImage,
      RightMenu,
		},
		data() {
			return {
        rightMenu: {
          show: false,
          pos: {
            x: 0,
            y: 0
          },
          items: [{
            key: 'TOP',
            name: '置顶',
            icon: 'el-icon-top'
          }, {
            key: 'QUIT',
            name: '退出',
            icon: 'el-icon-circle-close'
          }]
        }
      }
		},
		props: {
      regionGroup: {
				type: Object
			},
			active: {
				type: Boolean
			},
      menu:{
        type: Boolean,
        default: true
      },
		},
    methods: {
      showRightMenu(e) {
        this.rightMenu.pos = {
          x: e.x,
          y: e.y
        };
        this.rightMenu.show = "true";
      },
      onSelectMenu(item) {
        this.$emit(item.key.toLowerCase(), this.regionGroup);
      },
    }
	}
</script>

<style lang="scss" >
  .group-item {
    height: 50px;
    display: flex;
    margin-bottom: 1px;
    position: relative;
    padding: 5px;
    align-items: center;
    background-color: var(--bg-color);
    white-space: nowrap;
    cursor: pointer;

    &:hover {
      background-color: var(--active-color);
    }

    &.active {
      background-color: var(--active-color);
    }

    .group-avatar {
      width: 45px;
      height: 45px;
    }

    .group-info {
      flex: 1;
      display: flex;
      flex-direction: column;
      padding-left: 10px;
      text-align: left;
      overflow: hidden;

      .group-tag {
        display: flex;
        line-height: 22px;
        height: 22px;
      }

      .group-name {
        display: flex;
        line-height: 25px;
        height: 25px;
        font-weight: 600;
      }
    }
  }
</style>
